﻿
using System;
using System.Web.Mvc;
using ZFine.Application.Project;
using ZFine.Code;
using ZFine.Domain.Entity;
using ZFine.Web;

namespace Logiv.WEB.Areas.Project.Controllers
{
    public class ChargingStandardController : BaseController
    {
        private ChargingStandardApp server = new ChargingStandardApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = server.GetForm(keyValue);
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            try
            {
                var data = new
                {
                    rows = server.GetListlist(pagination, keyword),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            catch (Exception ex)
            {
                return null;
            }

        }
        [HttpPost]
        [HandlerAjaxOnly]
        //[ValidateAntiForgeryToken=false]
        [ValidateInput(false)]
        public ActionResult SubmitForm(ChargingStandardEntity SlideEntity, string keyValue)
        {
            int result = server.SubmitForm(SlideEntity, keyValue);
            if (result == -1)
            {
                return Error("报错了，请找张斌修改！");
            }
            else if (result == -2)
            {
                return Error("名字已重复，请重新填写");
            }
            else
            {
                return Success("操作成功。");
            }
        }

        public override ActionResult Form()
        {
            var keyValue = Request.QueryString["keyValue"];
            var data = server.GetForm(keyValue);
            if (data != null)
            {
                ViewData["objs"] = data;
            }
            else
            {
                ViewData["objs"] = null;
            }

            return View();
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            server.DeleteForm(keyValue);
            return Success("删除成功");
        }


    }
}
